function permutation(arr) {
    // 终止条件
    let used = []
    let res = []
    let path = []
    let index = 0

    function genPermutation() {
        // 终止条件
        if (path.length === arr.length) {
            res.push(path.slice())
            return
        }
        for (let i = 0; i < arr.length; i++) {
            const item = arr[i];
            if (used[item]) {
                continue
            }
            path.push(item)
            used[item] = true
            index++
            genPermutation()
            path.pop()
            used[item] = false
        }
    }
    genPermutation()
    return res
}

console.log(permutation([1, 2, 3]))